package modele;

import java.util.ArrayList;
import java.util.Collection;

import javax.annotation.Resource;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.ejb.TransactionManagement;
import javax.ejb.TransactionManagementType;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.transaction.UserTransaction;

@Stateless
@TransactionManagement(TransactionManagementType.BEAN)
public class FacadeInitSport {
	
	@PersistenceContext
	private EntityManager em;
	@EJB
	FacadeArticle fa = null;
	@EJB
	FacadeMembre fm = null;
	
	@Resource private UserTransaction ut;
	
	public void sports(){
		fa=new FacadeArticle();
		fm=new FacadeMembre();
		try {
			ut.begin();
			
			Sport foot = new Sport();
			foot.setName("Tennis");
			
			Collection<Competition> list = new ArrayList<Competition>();
		
			foot.setCompetitions(list);
			
			Sport foot2 = new Sport();
			foot2.setName("Basketball");
			foot2.setCompetitions(list);
			
			Sport foot3 = new Sport();
			foot3.setName("Cyclisme");
			foot3.setCompetitions(list);
			
			Sport foot4 = new Sport();
			foot4.setName("Golf");
			foot4.setCompetitions(list);
			
			Sport foot5 = new Sport();
			foot5.setName("Formule 1");
			foot5.setCompetitions(list);
			
			Sport foot6 = new Sport();
			foot6.setName("Football");
			foot6.setCompetitions(list);
			
			Sport foot7 = new Sport();
			foot7.setName("Rugby");
			foot7.setCompetitions(list);
			
			em.persist(foot);
			em.persist(foot2);
			em.persist(foot3);
			em.persist(foot4);
			em.persist(foot5);
			em.persist(foot6);
			em.persist(foot7);
			
		
			ut.commit();
			
			
		} catch (Exception e) {
			e.printStackTrace();
		} 
	
	}
	
	public void membre(){
		try {
		ut.begin();
		
		/*
		Membre m = new Membre();
		m.setMail("francois.fau82@etu.enseeiht.fr");
		m.setPrenom("Dj");
		m.setNom("Prenom");
		m.setPseudo("DjFF-Bis");
		m.setPassword("azerty");
		m.setActive(true);
		*/
		
		Membre m = new Membre();
		m.setMail("user1@test.com");
		m.setPrenom("user1Nom");
		m.setNom("user1Prenom");
		m.setPseudo("fabrice");
		m.setPassword("user1");
		m.setActive(true);
		em.persist(m);
		
		Membre m2 = new Membre();
		m2.setMail("user2@test.com");
		m2.setPrenom("user2Nom");
		m2.setNom("user2Prenom");
		m2.setPseudo("AxelBorg");
		m2.setPassword("user2");
		m2.setActive(true);
		em.persist(m2);
		
		Membre m3 = new Membre();
		m3.setMail("user3@test.com");
		m3.setPrenom("user3Nom");
		m3.setNom("user3Prenom");
		m3.setPseudo("Starbuz");
		m3.setPassword("user3");
		m3.setActive(true);
		em.persist(m3);
		
		Membre m4 = new Membre();
		m4.setMail("admin@test.com");
		m4.setPrenom("adminNom");
		m4.setNom("adminPrenom");
		m4.setPseudo("BigBoss");
		m4.setPassword("admin");
		m4.setActive(true);
		m4.augmenterPoints(5100);
		em.persist(m4);
		
		ut.commit();
		

		
		
		
		
		} catch (Exception e) {
			e.printStackTrace();
		} 
	}
	
	public void competitions(){
		
		Membre m=em.find(Membre.class, (long)4);
		
		
		fa.ajouterCompetition(m,Long.parseLong("7"), "TOP14");
		fa.ajouterCompetition(m,Long.parseLong("7"), "H-Cup");
		fa.ajouterCompetition(m,Long.parseLong("6"), "Ligue1");
		fa.ajouterCompetition(m,Long.parseLong("6"), "UEFA");
		fa.ajouterCompetition(m,Long.parseLong("1"), "Roland-Garros");
		fa.ajouterCompetition(m,Long.parseLong("1"), "Wimbledon");
		fa.ajouterCompetition(m,Long.parseLong("2"), "NBA");
		fa.ajouterCompetition(m,Long.parseLong("5"), "Grand Prix du Canada");
		fa.ajouterCompetition(m,Long.parseLong("3"), "Tour de France");
		fa.ajouterCompetition(m,Long.parseLong("4"), "PGA Tour");
	}
	
	
	
	
	
}
